#include <iostream>

using namespace std;

int maze[9][9] = {  { 2, 2, 2, 2, 2, 2, 2, 2, 2 },
										{ 2, 0, 0, 0, 0, 0, 0, 0, 2 },
										{ 2, 0, 2, 2, 0, 2, 2, 0, 2 },
										{ 2, 0, 2, 0, 0, 2, 0, 0, 2 },
										{ 2, 0, 2, 0, 2, 0, 2, 0, 2 },
										{ 2, 0, 0, 0, 0, 0, 2, 0, 2 },
										{ 2, 2, 0, 2, 2, 0, 2, 2, 2 },
										{ 2, 0, 0, 0, 0, 0, 0, 0, 2 },
										{ 2, 2, 2, 2, 2, 2, 2, 2, 2 } };

int In_i = 1, In_j = 1;
int Out_i = 7, Out_j = 7;

void visit(int i, int j)
{
	maze[i][j] = 1;

	if (i == Out_i && j == Out_j) {
		cout << "\n找到路劲为：\n";
		for (int x = 0; x < 9; x++) {
			for (int y = 0; y < 9; y++)	{
				if (maze[x][y] == 1)
					cout << "☆ ";
				else if (maze[x][y] == 2)
					cout << "██";
				else
					cout << "  ";
			}
			cout << endl;
		}
	}
	
	if (maze[i + 1][j] == 0)
		visit(i + 1, j);
	if (maze[i][j + 1] == 0)
		visit(i, j + 1);
	if (maze[i - 1][j] == 0)
		visit(i - 1, j);
	if (maze[i][j - 1] == 0)
		visit(i, j - 1);

	maze[i][j] = 0;
}

int main()
{
	cout << "显示迷宫：\n";
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++)	{
			if (maze[i][j] == 2)
				cout << "██";
			else
				cout << "  ";
		}
		cout << endl;
	}
	visit(In_i, In_j);
	
	return 0;
}